/*
2021-10-17
https://leetcode-cn.com/problems/simple-bank-system/
*/ 
class Bank {
public:
    vector<long long> balance;
    int idx=0;
    Bank(vector<long long>& b) {
        vector<long long> t(1e5+5,0);
        balance=t;
        for(auto t:b)
        {
            balance[++idx]=t;
        }
    }

    bool transfer(int account1, int account2, long long money) {
        if(account1>idx) return false;
        if(account2>idx) return false;
        if(balance[account1]>=money)
        {
            balance[account1]-=money;
            balance[account2]+=money;
            return true;
        }
        else return false;
    }

    bool deposit(int account, long long money) {
        if(account>idx) return false;
        balance[account]+=money;
        return true;
    }

    bool withdraw(int account, long long money) {
        if(account>idx) return false;
        if(balance[account]>=money)
        {
            balance[account]-=money;
            return true;
        }
        else return false;
    }
};

/**
 * Your Bank object will be instantiated and called as such:
 * Bank* obj = new Bank(balance);
 * bool param_1 = obj->transfer(account1,account2,money);
 * bool param_2 = obj->deposit(account,money);
 * bool param_3 = obj->withdraw(account,money);
 */

